import request from '@/utils/request'

// 登录
export function login (data) {
  return request({
    url: '/userLogin',
    method: 'post',
    data
  })
}

// 获取权限菜单
export function getMenus (data) {
  return request({
    url: '/getMenus',
    method: 'get',
    data
  })
}
// 获取用户列表
export function getUserList (data) {
  return request({
    url: '/getUserList',
    method: 'get',
    params: data
  })
}
// 更新用户状态
export function updateUserState (params) {
  return request({
    url: '/updateUserState',
    method: 'get',
    params
  })
}

// 添加用户
export function addUser (data) {
  return request({
    url: '/addUser',
    method: 'post',
    data
  })
}

// 根据id获取用户信息
export function getUser (id) {
  return request({
    url: `/getUser/${id}`,
    method: 'get'
  })
}

// 根据id编辑用户信息
export function editUser (id, data) {
  return request({
    url: `/editUser/${id}`,
    method: 'post',
    data
  })
}

// 根据id删除用户
export function deleteUser (id) {
  return request({
    url: `/deleteUser/${id}`,
    method: 'get'
  })
}

// 根据id删除用户
export function getRoles () {
  return request({
    url: '/getRoles',
    method: 'get'
  })
}

// 设置角色
export function setUserRole (userid, roleid) {
  return request({
    url: `/users/${userid}/role/${roleid}`,
    method: 'put'
  })
}

// 获取权限
export function rights (type) {
  return request({
    url: `/rights/${type}`,
    method: 'get'
  })
}

// 获取角色列表
export function roles () {
  return request({
    url: '/roles',
    method: 'get'
  })
}

// 删除角色里面的权限
export function deleteRightOfRole (roleid, rightid) {
  return request({
    url: `/roles/${roleid}/rights/${rightid}`,
    method: 'delete'
  })
}

// 分配权限
export function allotRights (roleid, data) {
  return request({
    url: `/roles/${roleid}/rights`,
    method: 'post',
    data
  })
}

// 添加和编辑角色
export function addOrEditRole (data) {
  return request({
    url: '/addOrEditRole',
    method: 'post',
    data
  })
}

// 分配权限
export function deleteRole (roleid) {
  return request({
    url: `/deleteRole/${roleid}`,
    method: 'get'
  })
}
